import { Collection, EntitySchema, Ref } from '@mikro-orm/core';
import { JobTasks } from './JobTasks';
import { OrderJobEnrolls } from './OrderJobEnrolls';

export class JobProjectJobs {
  id!: string;
  createdAt?: Date;
  updatedAt?: Date;
  task!: Ref<JobTasks>;
  name!: string;
  settleType?: string;
  priceType?: string;
  price?: number;
  num!: number;
  salary?: number;
  commission?: number;
  commissionUnit?: number;
  startTime!: string;
  endTime!: string;
  height?: number;
  sex?: string;
  age?: number;
  phone?: string;
  recruiter?: string;
  state?: string;
  bankAccount?: string;
  bankAddress?: string;
  enrolls = new Collection<OrderJobEnrolls>(this);
}

export const JobProjectJobsSchema = new EntitySchema({
  class: JobProjectJobs,
  properties: {
    id: { primary: true, type: 'string', columnType: 'bigint' },
    createdAt: { type: 'Date', length: 0, nullable: true },
    updatedAt: { type: 'Date', length: 0, nullable: true },
    task: {
      reference: 'm:1',
      entity: () => JobTasks,
      ref: true,
      onUpdateIntegrity: 'cascade',
      onDelete: 'cascade',
      index: 'id',
    },
    name: { type: 'string', length: 255 },
    settleType: { type: 'string', length: 255, nullable: true },
    priceType: { type: 'string', length: 255, nullable: true },
    price: { type: 'number', columnType: 'float', nullable: true },
    num: { type: 'number' },
    salary: { type: 'number', nullable: true },
    commission: { type: 'number', nullable: true },
    commissionUnit: { type: 'number', nullable: true },
    startTime: { type: 'string', columnType: 'time' },
    endTime: { type: 'string', columnType: 'time' },
    height: { type: 'number', nullable: true },
    sex: { type: 'string', length: 255, nullable: true },
    age: { type: 'number', nullable: true },
    phone: { type: 'string', length: 255, nullable: true },
    recruiter: { type: 'string', length: 255, nullable: true },
    state: { type: 'string', length: 255, nullable: true },
    bankAccount: { type: 'string', length: 255, nullable: true },
    bankAddress: { type: 'string', length: 255, nullable: true },
    enrolls: { reference: '1:m', entity: () => OrderJobEnrolls, mappedBy: 'expectedJob' },
  },
});
